﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemCenterSoa.IRepository.Attendance_Management;
using SystemCenterSoa.PoModel.Attendance_Management;
using SystemCenterSoa.Repository.CommonLib;
using Dapper;
using System.Data;
using System.Data.SqlClient;
using SystemCenterSoa.DtoModel.Attendance_Management;

namespace SystemCenterSoa.Repository.Attendance_Management
{
    public class AttendanceManagementRepository : BaseRepository, AttendanceManagementIRepository
    {
        public AttendanceManagementRepository(SystemCenterDbSoaContext systemCenterDbSoaContext) : base(systemCenterDbSoaContext)
        {
        }

        public int AskLeavePoAdd(ApplyLeavePo oneForm)
        {
            oneForm.application_type = "请假";
            oneForm.creator_date = DateTime.Now;
            _systemCenterDbSoaContext.ApplyLeavePo.Add(oneForm);
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int BusinessTravelRequestPoAdd(BusinessTravelRequestPo twoForm)
        {
            twoForm.application_type = "出差";
            twoForm.creator_date = DateTime.Now;
            _systemCenterDbSoaContext.BusinessTravelRequestPo.Add(twoForm);
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int FieldApplicationPoAdd(FieldApplicationPo threeForm)
        {
            threeForm.application_type = "外勤";
            threeForm.creator_date = DateTime.Now;
            _systemCenterDbSoaContext.FieldApplicationPo.Add(threeForm);
            return _systemCenterDbSoaContext.SaveChanges();

        }

        public int NotClockPoAdd(NotClockPo fourForm)
        {
            fourForm.application_type = "未打卡";
            fourForm.creator_date = DateTime.Now;
            _systemCenterDbSoaContext.NotClockPo.Add(fourForm);
            return _systemCenterDbSoaContext.SaveChanges();
        }
        public int CompanyActivitiesPoAdd(CompanyActivitiesPo fiveForm)
        {
            fiveForm.application_type = "公司活动";
            fiveForm.creator_date = DateTime.Now;
            _systemCenterDbSoaContext.CompanyActivitiesPo.Add(fiveForm);
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int DepartmentActivityPoAdd(DepartmentActivityPo sixForm)
        {
            sixForm.application_type = "部门活动";
            sixForm.creator_date = DateTime.Now;
            _systemCenterDbSoaContext.DepartmentActivityPo.Add(sixForm);
            return _systemCenterDbSoaContext.SaveChanges();
        }





        public int WorkOvertimeLeaveAdd(WorkOvertimeLeavePo sevenForm)
        {
            sevenForm.application_type = "加班离岗";
            sevenForm.creator_date = DateTime.Now;
            _systemCenterDbSoaContext.WorkOvertimeLeave.Add(sevenForm);
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public object GetAllApplicationType()
        {
            var one = _systemCenterDbSoaContext.ApplyLeavePo.Where(c => c.whether_through == 0).ToList();
            var two = _systemCenterDbSoaContext.BusinessTravelRequestPo.Where(c => c.whether_through == 0).ToList();
            var three = _systemCenterDbSoaContext.FieldApplicationPo.Where(c => c.whether_through == 0).ToList();
            var four = _systemCenterDbSoaContext.NotClockPo.Where(c => c.whether_through == 0).ToList();
            var five = _systemCenterDbSoaContext.CompanyActivitiesPo.Where(c => c.whether_through == 0).ToList();
            var six = _systemCenterDbSoaContext.DepartmentActivityPo.Where(c => c.whether_through == 0).ToList();
            var seven = _systemCenterDbSoaContext.WorkOvertimeLeave.Where(c => c.whether_through == 0).ToList();
            return new { one, two, three, four, five, six, seven };
        }
        public ApplyLeavePo Edit(int id)
        {
            var a = _systemCenterDbSoaContext.ApplyLeavePo.Find(id);
            return a;
        }
        public BusinessTravelRequestPo TwoEdit(int id)
        {
            var a = _systemCenterDbSoaContext.BusinessTravelRequestPo.Find(id);
            return a;
        }

        public FieldApplicationPo ThreeEdit(int id)
        {
            var a = _systemCenterDbSoaContext.FieldApplicationPo.Find(id);
            return a;
        }

        public NotClockPo FourEdit(int id)
        {
            var a = _systemCenterDbSoaContext.NotClockPo.Find(id);
            return a;
        }
        public CompanyActivitiesPo FiveEdit(int id)
        {
            var a = _systemCenterDbSoaContext.CompanyActivitiesPo.Find(id);
            return a;
        }

        public DepartmentActivityPo SixEdit(int id)
        {
            var a = _systemCenterDbSoaContext.DepartmentActivityPo.Find(id);
            return a;
        }


        public WorkOvertimeLeavePo SevenEdit(int id)
        {
            var a = _systemCenterDbSoaContext.WorkOvertimeLeave.Find(id);
            return a;
        }

        public object GetAllAskLeave(string depname, int year, int month, int pageIndex, int pageSize)
        {
            string sql = "select *from apply_leave where 1=1 and whether_through=0";
            string sqltwo = "select *from apply_leave where 1=1 and whether_through!=0";
            if (year > 0)
            {
                sql += " and  year(create_time)=@year ";
                sqltwo += " and  year(create_time)=@year ";
            }
            if (month > 0)
            {
                sql += "and  MONTH(create_time)=@month ";
                sqltwo += "and  MONTH(create_time)=@month ";
            }
            List<ApplyLeavePo> a = new List<ApplyLeavePo>();
            List<ApplyLeavePo> b = new List<ApplyLeavePo>();
            using (SqlConnection conn = new SqlConnection(Config))
            {
                a = conn.Query<ApplyLeavePo>(sql, new { @year = year, @month = month }).ToList();
                b = conn.Query<ApplyLeavePo>(sqltwo, new { @year = year, @month = month }).ToList();
            }
            if (!string.IsNullOrWhiteSpace(depname))
            {
                a = a.Where(c => c.subordinate_departments == depname).ToList();
                b = b.Where(c => c.subordinate_departments == depname).ToList();
            }
            int totalCount = a.Count();
            int totalCount2 = b.Count();
            a = a.OrderBy(c => c.leave_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            b = b.OrderBy(c => c.leave_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return new { a, b, totalCount, totalCount2 };
        }

        //获取出差信息

        public object GetAllBusinessTravelRequestPo(string depname, int year, int month, int pageIndex, int pageSize)
        {
            string sql = "select *from business_travel_request where 1=1 and whether_through=0";
            string sqltwo = "select *from business_travel_request where 1=1 and whether_through!=0";
            if (year > 0)
            {
                sql += " and  year(create_time)=@year ";
                sqltwo += " and  year(create_time)=@year ";
            }
            if (month > 0)
            {
                sql += "and  MONTH(create_time)=@month ";
                sqltwo += "and  MONTH(create_time)=@month ";
            }
            List<BusinessTravelRequestPo> a = new List<BusinessTravelRequestPo>();
            List<BusinessTravelRequestPo> b = new List<BusinessTravelRequestPo>();
            using (SqlConnection conn = new SqlConnection(Config))
            {
                a = conn.Query<BusinessTravelRequestPo>(sql, new { @year = year, @month = month }).ToList();
                b = conn.Query<BusinessTravelRequestPo>(sqltwo, new { @year = year, @month = month }).ToList();
            }
            if (!string.IsNullOrWhiteSpace(depname))
            {
                a = a.Where(c => c.subordinate_departments == depname).ToList();
                b = b.Where(c => c.subordinate_departments == depname).ToList();
            }
            int totalCount = a.Count();
            int totalCount2 = b.Count();
            a = a.OrderBy(c => c.business_travel_request_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            b = b.OrderBy(c => c.business_travel_request_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return new { a, b, totalCount, totalCount2 };
        }


        public object GetAllFieldApplicationPo(string depname, int year, int month, int pageIndex, int pageSize)
        {
            string sql = "select *from field_application where 1=1 and whether_through=0";
            string sqltwo = "select *from field_application where 1=1 and whether_through!=0";
            if (year > 0)
            {
                sql += " and  year(create_time)=@year ";
                sqltwo += " and  year(create_time)=@year ";
            }
            if (month > 0)
            {
                sql += "and  MONTH(create_time)=@month ";
                sqltwo += "and  MONTH(create_time)=@month ";
            }
            List<FieldApplicationPo> a = new List<FieldApplicationPo>();
            List<FieldApplicationPo> b = new List<FieldApplicationPo>();
            using (SqlConnection conn = new SqlConnection(Config))
            {
                a = conn.Query<FieldApplicationPo>(sql, new { @year = year, @month = month }).ToList();
                b = conn.Query<FieldApplicationPo>(sqltwo, new { @year = year, @month = month }).ToList();
            }
            if (!string.IsNullOrWhiteSpace(depname))
            {
                a = a.Where(c => c.subordinate_departments == depname).ToList();
                b = b.Where(c => c.subordinate_departments == depname).ToList();
            }
            int totalCount = a.Count();
            int totalCount2 = b.Count();
            a = a.OrderBy(c => c.field_application_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            b = b.OrderBy(c => c.field_application_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return new { a, b, totalCount, totalCount2 };
        }


        public object GetAllNotClockPo(string depname, int year, int month, int pageIndex, int pageSize)
        {
            string sql = "select *from not_clock where 1=1 and whether_through=0";
            string sqltwo = "select *from not_clock where 1=1 and whether_through!=0";
            if (year > 0)
            {
                sql += " and  year(create_time)=@year ";
                sqltwo += " and  year(create_time)=@year ";
            }
            if (month > 0)
            {
                sql += "and  MONTH(create_time)=@month ";
                sqltwo += "and  MONTH(create_time)=@month ";
            }
            List<NotClockPo> a = new List<NotClockPo>();
            List<NotClockPo> b = new List<NotClockPo>();
            using (SqlConnection conn = new SqlConnection(Config))
            {
                a = conn.Query<NotClockPo>(sql, new { @year = year, @month = month }).ToList();
                b = conn.Query<NotClockPo>(sqltwo, new { @year = year, @month = month }).ToList();
            }
            if (!string.IsNullOrWhiteSpace(depname))
            {
                a = a.Where(c => c.subordinate_departments == depname).ToList();
                b = b.Where(c => c.subordinate_departments == depname).ToList();
            }
            int totalCount = a.Count();
            int totalCount2 = b.Count();
            a = a.OrderBy(c => c.not_clock_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            b = b.OrderBy(c => c.not_clock_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return new { a, b, totalCount, totalCount2 };
        }


        public object GetAllCompanyActivitiesPo(string depname, int year, int month, int pageIndex, int pageSize)
        {
            string sql = "select *from company_activities where 1=1 and whether_through=0";
            string sqltwo = "select *from company_activities where 1=1 and whether_through!=0";
            if (year > 0)
            {
                sql += " and  year(create_time)=@year ";
                sqltwo += " and  year(create_time)=@year ";
            }
            if (month > 0)
            {
                sql += "and  MONTH(create_time)=@month ";
                sqltwo += "and  MONTH(create_time)=@month ";
            }
            List<CompanyActivitiesPo> a = new List<CompanyActivitiesPo>();
            List<CompanyActivitiesPo> b = new List<CompanyActivitiesPo>();
            using (SqlConnection conn = new SqlConnection(Config))
            {
                a = conn.Query<CompanyActivitiesPo>(sql, new { @year = year, @month = month }).ToList();
                b = conn.Query<CompanyActivitiesPo>(sqltwo, new { @year = year, @month = month }).ToList();
            }
            if (!string.IsNullOrWhiteSpace(depname))
            {
                a = a.Where(c => c.subordinate_departments == depname).ToList();
                b = b.Where(c => c.subordinate_departments == depname).ToList();
            }
            int totalCount = a.Count();
            int totalCount2 = b.Count();
            a = a.OrderBy(c => c.company_activities_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            b = b.OrderBy(c => c.company_activities_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return new { a, b, totalCount, totalCount2 };
        }


        public object GetAllDepartmentActivityPo(string depname, int year, int month, int pageIndex, int pageSize)
        {
            string sql = "select *from department_activity where 1=1 and whether_through=0";
            string sqltwo = "select *from department_activity where 1=1 and whether_through!=0";
            if (year > 0)
            {
                sql += " and  year(create_time)=@year ";
                sqltwo += " and  year(create_time)=@year ";
            }
            if (month > 0)
            {
                sql += "and  MONTH(create_time)=@month ";
                sqltwo += "and  MONTH(create_time)=@month ";
            }
            List<DepartmentActivityPo> a = new List<DepartmentActivityPo>();
            List<DepartmentActivityPo> b = new List<DepartmentActivityPo>();
            using (SqlConnection conn = new SqlConnection(Config))
            {
                a = conn.Query<DepartmentActivityPo>(sql, new { @year = year, @month = month }).ToList();
                b = conn.Query<DepartmentActivityPo>(sqltwo, new { @year = year, @month = month }).ToList();
            }
            if (!string.IsNullOrWhiteSpace(depname))
            {
                a = a.Where(c => c.subordinate_departments == depname).ToList();
                b = b.Where(c => c.subordinate_departments == depname).ToList();
            }
            int totalCount = a.Count();
            int totalCount2 = b.Count();
            a = a.OrderBy(c => c.department_activity_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            b = b.OrderBy(c => c.department_activity_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return new { a, b, totalCount, totalCount2 };
        }

        public object GetAllWorkOvertimeLeavePo(string depname, int year, int month, int pageIndex, int pageSize)
        {
            string sql = "select *from work_overtime_leave where 1=1 and whether_through=0";
            string sqltwo = "select *from work_overtime_leave where 1=1 and whether_through!=0";
            if (year > 0)
            {
                sql += " and  year(create_time)=@year ";
                sqltwo += " and  year(create_time)=@year ";
            }
            if (month > 0)
            {
                sql += "and  MONTH(create_time)=@month ";
                sqltwo += "and  MONTH(create_time)=@month ";
            }
            List<WorkOvertimeLeavePo> a = new List<WorkOvertimeLeavePo>();
            List<WorkOvertimeLeavePo> b = new List<WorkOvertimeLeavePo>();
            using (SqlConnection conn = new SqlConnection(Config))
            {
                a = conn.Query<WorkOvertimeLeavePo>(sql, new { @year = year, @month = month }).ToList();
                b = conn.Query<WorkOvertimeLeavePo>(sqltwo, new { @year = year, @month = month }).ToList();
            }
            if (!string.IsNullOrWhiteSpace(depname))
            {
                a = a.Where(c => c.subordinate_departments == depname).ToList();
                b = b.Where(c => c.subordinate_departments == depname).ToList();
            }
            int totalCount = a.Count();
            int totalCount2 = b.Count();
            a = a.OrderBy(c => c.work_overtime_leave_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            b = b.OrderBy(c => c.work_overtime_leave_id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return new { a, b, totalCount, totalCount2 };
        }

        //获取请假单条数据   审核
        public int AskLeaveAudit(int status, int id, string modifi_name)
        {
            var info = _systemCenterDbSoaContext.ApplyLeavePo.Find(id);
            info.whether_through = status; info.modifi_name = modifi_name; info.modifi_date = DateTime.Now;
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int BusinessTravelRequestPoAudit(int status, int id, string modifi_name)
        {
            var info = _systemCenterDbSoaContext.BusinessTravelRequestPo.Find(id);
            info.whether_through = status; info.modifi_name = modifi_name; info.modifi_date = DateTime.Now;
            return _systemCenterDbSoaContext.SaveChanges();
        }


        public int FieldApplicationPoAudit(int status, int id, string modifi_name)
        {
            var info = _systemCenterDbSoaContext.FieldApplicationPo.Find(id);
            info.whether_through = status; info.modifi_name = modifi_name; info.modifi_date = DateTime.Now;
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int NotClockPoAudit(int status, int id, string modifi_name)
        {
            var info = _systemCenterDbSoaContext.NotClockPo.Find(id);
            info.whether_through = status; info.modifi_name = modifi_name; info.modifi_date = DateTime.Now;
            return _systemCenterDbSoaContext.SaveChanges();
        }


        public int CompanyActivitiesPoAudit(int status, int id, string modifi_name)
        {
            var info = _systemCenterDbSoaContext.CompanyActivitiesPo.Find(id);
            info.whether_through = status; info.modifi_name = modifi_name; info.modifi_date = DateTime.Now;
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int DepartmentActivityPoAudit(int status, int id, string modifi_name)
        {
            var info = _systemCenterDbSoaContext.DepartmentActivityPo.Find(id);
            info.whether_through = status; info.modifi_name = modifi_name; info.modifi_date = DateTime.Now;
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int WorkOvertimeLeavePoAudit(int status, int id, string modifi_name)
        {
            var info = _systemCenterDbSoaContext.WorkOvertimeLeave.Find(id);
            info.whether_through = status; info.modifi_name = modifi_name; info.modifi_date = DateTime.Now;
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int AskLeaveDelete(List<int> ids)
        {
            foreach (var id in ids)
            {
                var info = _systemCenterDbSoaContext.ApplyLeavePo.Find(id);
                if (info.whether_through == 0)
                {
                    _systemCenterDbSoaContext.ApplyLeavePo.Remove(info);
                }
            }
            return _systemCenterDbSoaContext.SaveChanges();
        }


        public int BusinessTravelRequestPoDelete(List<int> ids)
        {
            foreach (var id in ids)
            {
                var info = _systemCenterDbSoaContext.BusinessTravelRequestPo.Find(id);
                if (info.whether_through == 0)
                {
                    _systemCenterDbSoaContext.BusinessTravelRequestPo.Remove(info);
                }
            }
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int FieldApplicationPoDelete(List<int> ids)
        {
            foreach (var id in ids)
            {
                var info = _systemCenterDbSoaContext.FieldApplicationPo.Find(id);
                if (info.whether_through == 0)
                {
                    _systemCenterDbSoaContext.FieldApplicationPo.Remove(info);
                }
            }
            return _systemCenterDbSoaContext.SaveChanges();
        }


        public int NotClockPoDelete(List<int> ids)
        {
            foreach (var id in ids)
            {
                var info = _systemCenterDbSoaContext.NotClockPo.Find(id);
                if (info.whether_through == 0)
                {
                    _systemCenterDbSoaContext.NotClockPo.Remove(info);
                }
            }
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int CompanyActivitiesPoDelete(List<int> ids)
        {
            foreach (var id in ids)
            {
                var info = _systemCenterDbSoaContext.CompanyActivitiesPo.Find(id);
                if (info.whether_through == 0)
                {
                    _systemCenterDbSoaContext.CompanyActivitiesPo.Remove(info);
                }
            }
            return _systemCenterDbSoaContext.SaveChanges();
        }


        public int DepartmentActivityPoDelete(List<int> ids)
        {
            foreach (var id in ids)
            {
                var info = _systemCenterDbSoaContext.DepartmentActivityPo.Find(id);
                if (info.whether_through == 0)
                {
                    _systemCenterDbSoaContext.DepartmentActivityPo.Remove(info);
                }
            }
            return _systemCenterDbSoaContext.SaveChanges();
        }


        public int WorkOvertimeLeavePoDelete(List<int> ids)
        {
            foreach (var id in ids)
            {
                var info = _systemCenterDbSoaContext.WorkOvertimeLeave.Find(id);
                if (info.whether_through == 0)
                {
                    _systemCenterDbSoaContext.WorkOvertimeLeave.Remove(info);
                }
            }
            return _systemCenterDbSoaContext.SaveChanges();
        }


        ///////////////////修改
        public int AskLeavePoUpdate(ApplyLeavePo form)
        {
            _systemCenterDbSoaContext.Entry(form).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges();
        }
        public int BusinessTravelRequestPoUpdate(BusinessTravelRequestPo form)
        {
            _systemCenterDbSoaContext.Entry(form).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges();
        }
        public int FieldApplicationPoUpdate(FieldApplicationPo form)
        {
            _systemCenterDbSoaContext.Entry(form).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges();
        }
        public int NotClockPoUpdate(NotClockPo form)
        {
            _systemCenterDbSoaContext.Entry(form).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges();
        }
        public int CompanyActivitiesPoUpdate(CompanyActivitiesPo form)
        {
            _systemCenterDbSoaContext.Entry(form).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges();
        }
        public int DepartmentActivityPUpdate(DepartmentActivityPo form)
        {
            _systemCenterDbSoaContext.Entry(form).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public int WorkOvertimeLeaveUpdate(WorkOvertimeLeavePo form)
        {
            _systemCenterDbSoaContext.Entry(form).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges();
        }

        public List<AnnualLeaveStatisticsDto> GetAllAnnualLeaveStatisticsDto(string depname, string name, int year)
        {
            var a = _systemCenterDbSoaContext.AnnualLeaveStatisticsPo.AsQueryable();
            var b = _systemCenterDbSoaContext.PeoplePo.AsQueryable();
            var list = from A in a
                       join B in b on A.annual_leave_account equals B.people_management_loginname//跟账号相匹配
                       select new AnnualLeaveStatisticsDto
                       {
                           annual_leave_account = A.annual_leave_account,
                           annual_leave_id = A.annual_leave_id,
                           eight = A.eight,
                           eleven = A.eleven,
                           five = A.five,
                           four = A.four,
                           fourteen = A.fourteen,
                           last_year_hour = A.last_year_hour,
                           nine = A.nine,
                           one = A.one,
                           seven = A.seven,
                           six = A.six,
                           ten = A.ten,
                           thirteen = A.thirteen,
                           this_year_day = A.this_year_day,
                           this_year_hour = A.this_year_hour,
                           three = A.three,
                           twelve = A.twelve,
                           two = A.two,
                           depname = B.people_management_department_name,
                           name = B.people_management_name,
                           creator_date = A.creator_date

                       };
            if (!string.IsNullOrWhiteSpace(depname))
            {
                list = list.Where(c => c.depname == depname);
            }
            if (!string.IsNullOrWhiteSpace(name))
            {
                list = list.Where(c => c.name.Contains(name));
            }
            if (year > 0)
            {
                list = list.Where(c => c.creator_date.Year == year);
            }
            return list.ToList();
        }

        public List<DepartmentOvertimeManagementPo> GetDepartmentOvertimeManagementPo(string depname, int year, int month)
        {
            var a = _systemCenterDbSoaContext.DepartmentOvertimeManagementPo.Where(c => c.depname == depname).ToList();
            a = a.Where(c => c.year == year).ToList();
            a = a.Where(c => c.month == month).ToList();
            return a;
        }

        //员工出勤显示
        public List<EmployeeAttendanceSettingsPo> GetAllEmployeeAttendanceSettingsPo(string depname, int year, string username)
        {
            var a = _systemCenterDbSoaContext.EmployeeAttendanceSettingsPo.Where(c => c.depname == depname).ToList();
            a = a.Where(c => c.year == year).ToList();
            if (!string.IsNullOrWhiteSpace(username))
            {
                a = a.Where(c => c.user_name.Contains(username)).ToList();
            }
            return a;
        }

        public int UpdateEmployeeAttendanceSettingsPo(List<EmployeeAttendanceSettingsPo> tabledata)
        {
            foreach (var item in tabledata)
            {
                _systemCenterDbSoaContext.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }
            return _systemCenterDbSoaContext.SaveChanges();

        }

        //部门经理设置
        public List<DepartmentListPo> GetDepartmentListPo()
        {
            return _systemCenterDbSoaContext.DepartmentListPo.ToList();
        }

        //节假日设置

        public object GetHolidaySettingsPo(int year)
        {
            var data = _systemCenterDbSoaContext.HolidaySettingsPo.Where(c => c.holiday_season.Value.Year == year).ToList();
            var list = _systemCenterDbSoaContext.HolidaySettingsPo.Where(c => c.special_working_day.Value.Year == year).ToList();
            return new { data, list };
        }
        //节假日
        public int AddHolidaySeason(DateTime date)
        {
            HolidaySettingsPo form = new HolidaySettingsPo();
            form.holiday_season = date;
            _systemCenterDbSoaContext.Add(form);
            return _systemCenterDbSoaContext.SaveChanges();
        }
        public int DeleteHolidaySettingsPo(int id)
        {
            _systemCenterDbSoaContext.HolidaySettingsPo.Remove(_systemCenterDbSoaContext.HolidaySettingsPo.Find(id));
            return _systemCenterDbSoaContext.SaveChanges();
        }

        //特殊工作日
        public int AddSpecialWorkingDay(DateTime date)
        {
            HolidaySettingsPo form = new HolidaySettingsPo();
            form.special_working_day = date;
            _systemCenterDbSoaContext.Add(form);
            return _systemCenterDbSoaContext.SaveChanges();
        }
        //年假设置
        public List<AnnualLeaveSetPo> GetAnnualLeaveSetPo(string depname, int year)
        {
            var data = _systemCenterDbSoaContext.AnnualLeaveSetPo.Where(c => c.depname == depname);
            data = data.Where(c => c.year == year);
            return data.ToList();
        }

        public int UpdateAnnualLeaveSetPo(List<AnnualLeaveSetPo> tabledata)
        {
            foreach (var item in tabledata)
            {
                _systemCenterDbSoaContext.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }
            return _systemCenterDbSoaContext.SaveChanges();
        }

        //上传考勤
        public List<UploadAttendancePo> GetUploadAttendancePo(int year, int month)
        {
            var data = _systemCenterDbSoaContext.UploadAttendancePo.Where(c => c.creator_time.Value.Year == year);
            data = data.Where(c => c.creator_time.Value.Month == month);
            return data.ToList();
        }

        public int AddUploadAttendancePo(string name)
        {
            UploadAttendancePo form = new UploadAttendancePo();
            form.creator_time = DateTime.Now;
            form.authorized_personnel = name;
            _systemCenterDbSoaContext.UploadAttendancePo.Add(form);
            return _systemCenterDbSoaContext.SaveChanges();
        }


        public List<ComprehensiveStatisticsContractsProjectsPo> GetComprehensiveStatisticsContractsProjectsPo(string depname, int year)
        {
                var a = _systemCenterDbSoaContext.ComprehensiveStatisticsContractsProjectsPo.ToList();
            
          
            if (!string.IsNullOrWhiteSpace(depname))
            {
                a = a.Where(c => c.depname == depname).ToList();
            }
            if (year > 0)
            {
                a = a.Where(c => c.year == year).ToList();
            }
           
            return a;
        }
    }
}



















